// CPortSetupDlg.h
//
// Copyright (c) gulian lin.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#pragma once

#include "USB_DevInfo.h"
#include "resource.h"
#include <vector>

class CPortSetupDlg : public CDialogImpl<CPortSetupDlg>
{
private:
	std::vector<USB_DevInfo> usb_dev_list_;
	std::wstring port_name_;
	CImageList icon_list_;
	CComboBoxEx port_combo_;
	CComboBox baudrate_combo_;
	CEdit dev_desc_edit_;
	CEdit dev_mfg_edit_;
	HDEVNOTIFY dev_notify_handle_;
	CComboBox capa_baudrate;
	CComboBox settable_params;
	CEdit sub_type;
	CComboBox dev_capas;

public:
	enum { IDD = IDD_PORTSETUPDLG };

	BEGIN_MSG_MAP(CMainDlg)
		MSG_WM_INITDIALOG(OnInitDialog)
		MSG_WM_DEVICECHANGE(OnDeviceChange)
		MSG_WM_CLOSE(OnClose)
		COMMAND_ID_HANDLER(IDC_OPEN_BUTTON, OnOpen)
		COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
		COMMAND_HANDLER(IDC_COMCOMBO, CBN_SELCHANGE, OnSelectChange)
	END_MSG_MAP()

	LRESULT OnInitDialog(CWindow wndFocus, LPARAM lInitPara);
	LRESULT OnDeviceChange(UINT nEventType, DWORD dwData);
	void OnClose();
	LRESULT OnOpen(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnSelectChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	void InitControl();
	void GetSysPort();
	bool GetComCapability(USB_DevInfo *dev_info);
	int InsertPortItem(const std::wstring &str, int num_item, int num_icon);
};
